

import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;
//package de.vogella.jfreechart.swing.pie;


public class Wykres extends JFrame {

	
	private static final long serialVersionUID = 1L;

	public Wykres(String applicationTitle, String chartTitle, int w, int p) {
        super(applicationTitle);
        PieDataset dataset = createDataset(w, p);
        JFreeChart chart = createChart(dataset, chartTitle);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
        setContentPane(chartPanel);

    }

    private  PieDataset createDataset(int w, int p) {
    	if (w + p == 99){ p = p + 1; }
        DefaultPieDataset result = new DefaultPieDataset();
        result.setValue(("Wydatki :" + w + " %"), w);
        result.setValue(("Przychody :" + p + " %"), p);
        return result;
        
    }
    
    private JFreeChart createChart(PieDataset dataset, String title) {
        
        JFreeChart chart = ChartFactory.createPieChart3D(title,  				
            dataset,                
            true,                   
            true,
            false);

        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        return chart;
        
    }
}